package activity

import android.view.View
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.LinearLayoutManager
import apdate.SquareApdate
import com.wd.common.base.BaseActivity
import com.wd.common.viewmodel.MyViewModel
import com.wd.rim.databinding.ActivityDriversBinding

class DriversActivity : BaseActivity<ActivityDriversBinding,Any?>() {
    val mViewModel:MyViewModel by viewModels()
    private var apdate:SquareApdate?=null
    override fun getViewBinding()=ActivityDriversBinding.inflate(layoutInflater)

    override fun initData() {
        val intent=intent
        val Name = intent.getStringExtra("name")
        val Hearpic = intent.getStringExtra("hearpic")
        binding.name.setText(Name)
        binding.aa.setImageBitmap(Hearpic)

        mViewModel.getRecom(1,10)
        mViewModel.Recom.observe(this){
            apdate=this?.let {it1-> SquareApdate(it1,it) }
            binding.recyId.layoutManager=LinearLayoutManager(this)
            binding.recyId.adapter=apdate
        }

        binding.WGuan.setOnClickListener {
            binding.WGuan.visibility= View.GONE
            binding.Guan.visibility=View.VISIBLE
            Toast.makeText(this,"已关注",Toast.LENGTH_SHORT).show()
        }

        binding.Guan.setOnClickListener {
            val builder = AlertDialog.Builder(this)
            builder.setTitle("确定要取消关注吗")
            builder.setPositiveButton("确定") { dialog, which ->

                Toast.makeText(this, "取消成功", Toast.LENGTH_SHORT).show()
                binding.WGuan.visibility= View.VISIBLE
                binding.Guan.visibility=View.GONE
            }
            builder.setNegativeButton("取消", null)
            builder.setCancelable(true)
            builder.show()

        }
    }

}

private fun ImageView.setImageBitmap(hearpic: String?) {

}
